home *** CD-ROM | disk | FTP | other *** search
- { ed.pas -- Edit controls demonstration }
-
- program Ed;
-
- {$R ed.res}
-
- uses WinTypes, WinProcs, WObjects, Strings;
-
- const
-
- id_Menu = 100; { Menu resource ID }
- cm_Dialog = 101; { Dialog-command ID }
- id_Dialog = 200; { Dialog resource ID }
-
- id_ed1 = 101; { Single-line edit control ID }
- id_ed2 = 102; { Multiple-line edit control ID }
- id_ed3 = 103; { Password edit control ID }
-
- ed1Len = 80; { Maximum length of single-line control }
- ed2Len = 2048; { Maximum length of multiple-line control }
- ed3Len = 20; { Maximum length of password control }
-
- type
-
- PDialogRec = ^DialogRec; { Pointer to DialogRec record }
- DialogRec = record
- SingleLine: array[0 .. ed1Len] of Char;
- MultiLine: array[0 .. ed2Len] of Char;
- Password: array[0 .. ed3Len] of Char;
- end;
-
- PEdDialog = ^EdDialog;
- EdDialog = object(TDialog)
- DataPointer: PDialogRec;
- constructor Init(AParent: PWindowsObject; AName: PChar;
- P: PDialogRec);
- procedure SetupWindow; virtual;
- procedure Ok(var Msg: TMessage);
- virtual id_First + id_Ok;
- end;
-
- EdApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PEdWindow = ^EdWindow;
- EdWindow = object(TWindow)
- DialogData: DialogRec;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure CMDialog(var Msg: TMessage);
- virtual cm_First + cm_Dialog;
- end;
-
-
- { Common procedures }
-
- {- Initialize edit control identified by CtrlID with text in Buffer.
- HDlg is the dialog window handle; MaxLen is the maximum number of
- characters that can be entered into the control.}
-
- procedure SetText(HDlg: HWnd; CtrlID: Word; Buffer: PChar;
- MaxLen: Word);
- begin
- SendDlgItemMessage(HDlg, CtrlID, wm_SetText, 0, LongInt(Buffer));
- SendDlgItemMessage(HDlg, CtrlID, em_LimitText, MaxLen, 0)
- end;
-
- {- Retrieve text from edit control identified by CtrlID. Text is
- copied to the array addressed by Buffer. MaxLen equals the maximum
- number of bytes to copy, including the null terminator.}
-
- procedure GetText(HDlg: HWnd; CtrlID: Word; Buffer: PChar;
- MaxLen: Word);
- begin
- SendDlgItemMessage(HDlg, CtrlID, wm_GetText, MaxLen,
- LongInt(Buffer))
- end;
-
-
- { EdDialog }
-
- {- Construct EdDialog instance. P addresses dialog data record. }
- constructor EdDialog.Init(AParent: PWindowsObject; AName: PChar;
- P: PDialogRec);
- begin
- TDialog.Init(AParent, AName);
- DataPointer := P { Save pointer to caller's dialog record }
- end;
-
- {- Prepare initial control values }
- procedure EdDialog.SetupWindow;
- var
- I: Integer;
- begin
- TDialog.SetupWindow;
- with DataPointer^ do
- begin
- SetText(HWindow, id_Ed1, SingleLine, ed1Len);
- SetText(HWindow, id_Ed2, MultiLine, ed2Len);
- SetText(HWindow, id_Ed3, Password, ed3Len)
- end
- end;
-
- {- Respond to Ok button }
- procedure EdDialog.Ok(var Msg: TMessage);
- var
- TempPassword: array[0 .. ed3Len] of Char;
- begin
- GetText(HWindow, id_Ed3, TempPassword, Sizeof(TempPassword));
- if StrIComp(TempPassword, 'Password') <> 0 then
- begin
- MessageBeep(0);
- MessageBox(HWindow,
- 'Incorrect password! (Enter "Password" in Password field)',
- 'Error', mb_Ok)
- end else
- begin
- with DataPointer^ do
- begin
- GetText(HWindow, id_Ed1, SingleLine, Sizeof(SingleLine));
- GetText(HWindow, id_Ed2, MultiLine, Sizeof(MultiLine));
- GetText(HWindow, id_Ed3, Password, Sizeof(Password))
- end;
- TDialog.Ok(Msg)
- end
- end;
-
-
- { EdApplication }
-
- {- Initialize EdApplication object's window }
- procedure EdApplication.InitMainWindow;
- begin
- MainWindow := New(PEdWindow, Init(nil, 'Ed'))
- end;
-
-
- { EdWindow }
-
- {- Construct EdWindow object }
- constructor EdWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
- with DialogData do
- begin
- StrCopy(SingleLine, 'Single-line string');
- StrCopy(MultiLine, 'Multiple-line string');
- StrCopy(Password, 'xxxxx')
- end
- end;
-
- {- Execute Menu:Dialog command }
- procedure EdWindow.CMDialog(var Msg: TMessage);
- begin
- Application^.ExecDialog(New(PEdDialog,
- Init(@Self, PChar(id_Dialog), @DialogData)))
- end;
-
- var
-
- EdApp: EdApplication;
-
- begin
- EdApp.Init('EdApp');
- EdApp.Run;
- EdApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 3/20/1991
- ---------------------------------------------------------------}
-